
#include "StdAfx.h"
#include "RoomToRoom_Default.h"
#include "board_define.h"
#include "User.h"
#include "Room.h"
#include "LobbyService.h"

int RoomToRoom_Default::enter( const char* data, User* user, Room* to_room ){	
	int result = RoomToRoom_Decorator::enter( data, user, to_room );
	if( result )
		return result;

	if(! user )
		return DEF_ERROR_NO_USER;

	if(! to_room )
		return DEF_ERROR_NO_ROOM;

	Room* current_room = user->getRoom();
	if(! current_room )
		return DEF_ERROR_NO_ROOM;
	
	RoomExit* roomExit = LobbyService::Instance()->getRoomExit();
	result = roomExit->exit( user, 0, false, true );
	if( result )
		return result;	

	RoomEnter* roomEnter = LobbyService::Instance()->getRoomEnter();	
	result = roomEnter->enter( to_room->getIdent(), user, 0, to_room->getPasswd(), 0 );
	if( result )
		return result;

	return DEFAULT_SUCCESS;
}
